package com.piggy.logi.sys.controller;

import java.util.List;
import java.util.Arrays;

import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.vo.LogiKefuFineExtVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.vo.LogiKefuFineVo;
import com.piggy.logi.sys.bo.LogiKefuFineQueryBo;
import com.piggy.logi.sys.bo.LogiKefuFineEditBo;
import com.piggy.logi.sys.service.ILogiKefuFineService;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.piggy.common.core.domain.R;
import java.lang.Integer;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * 罚款问题登记Controller
 *
 * @author piggy
 * @date 2023-10-25
 */
@Api(value = "罚款问题登记控制器", tags = {"罚款问题登记管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/fine")
public class LogiKefuFineController extends BaseController {

    private final ILogiKefuFineService iLogiKefuFineService;

    /**
     * 查询罚款问题登记列表
     */
    @ApiOperation("查询罚款问题登记列表")
    //@SaCheckPermission("sys:fine:list")
    @GetMapping("/list")
    public TableDataInfo<LogiKefuFineExtVo> list(@Validated LogiKefuFineQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiKefuFineService.queryPageList(bo);
    }

    /**
     * 导出罚款问题登记列表
     */
    @ApiOperation("导出罚款问题登记列表")
    //@SaCheckPermission("sys:fine:export")
    @Log(title = "罚款问题登记", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiKefuFineQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiKefuFineExtVo> list = iLogiKefuFineService.queryList(bo);
        ExcelUtil<LogiKefuFineExtVo> util = new ExcelUtil<LogiKefuFineExtVo>(LogiKefuFineExtVo.class);
        util.exportExcel(response, list, "罚款问题登记");
    }

    /**
     * 获取罚款问题登记详细信息
     */
    @ApiOperation("获取罚款问题登记详细信息")
    //@SaCheckPermission("sys:fine:query")
    @GetMapping("/{id}")
    public R<LogiKefuFineVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiKefuFineService.queryById(id));
    }

    /**
     * 新增罚款问题登记
     */
    @ApiOperation("新增罚款问题登记")
    //@SaCheckPermission("sys:fine:add")
    @Log(title = "罚款问题登记", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiKefuFineVo> add(@Validated @RequestBody LogiKefuFineEditBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiKefuFineService.insertByAddBo(bo));
    }

    /**
     * 修改罚款问题登记
     */
    @ApiOperation("修改罚款问题登记")
    //@SaCheckPermission("sys:fine:edit")
    @Log(title = "罚款问题登记", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiKefuFineVo> edit(@Validated @RequestBody LogiKefuFineEditBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return R.ok(iLogiKefuFineService.updateByEditBo(bo));
    }

    /**
     * 删除罚款问题登记
     */
    @ApiOperation("删除罚款问题登记")
    //@SaCheckPermission("sys:fine:remove")
    @Log(title = "罚款问题登记" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiKefuFineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
